const enterpriseVue = new Vue({
  el: '#app',
  data() {
    var checkIDCard = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('身份证号不能为空'));
      }
      setTimeout(() => {
        if (!ID_Validity(value)) {
          callback(new Error('请输入正确的身份证号'));
        }
      }, 100);
    }
    return {
      pickerOptions: pickerOptions,
      rules: {
        Employee_Name: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
        Service_Category: [{ required: true, message: '请选择服务类型', trigger: 'blur', }],
        Mobile: [{ required: true, message: '请输入手机号', trigger: 'blur', }],
        Gender: [{ required: true, message: '请选择性别', trigger: 'blur', }],
        Nation: [{ required: true, message: '请选择民族', trigger: 'blur', }],
        Education: [{ required: true, message: '请选择学历', trigger: 'blur', }],
        Residence_Address: [{ required: true, message: '请输入户籍地址', trigger: 'blur', }],
        Current_Residence_Address: [{ required: true, message: '请输入现住址', trigger: 'blur', }],
        Household_Register_Class: [{ required: true, message: '请输入户口性质', trigger: 'blur', }],
        Entry_Date: [{ required: true, message: '请选择入职日期', trigger: 'blur', }],
        Departure_Date: [{ required: true, message: '请选择离职日期', trigger: 'blur', }],
        Contract_SerialNumber: [{ required: true, message: '请输入合同流水号', trigger: 'blur', }],
        ID_Number: [{
          validator: checkIDCard,
          trigger: 'blur'
        }],
      },
      Service_Category: ['送货员'],
      form: {
        Employee_SerialNumber: "",
        Employee_Name: '',
        Service_Category: '',
        Mobile: '',
        ID_Number: '',
        Gender: '',
        Nation: '',
        Education: '',
        Residence_Address: '',
        Current_Residence_Address: '',
        Household_Register_Class: '',
        Entry_Date: '',
        Departure_Date: '',
        Contract_SerialNumber: '',
        Supplementary_Insurance: 0,
        Enterprise_Info_SerialNumber: $.cookie("enterprise"),
        // Children: {
        //   employee_id: [{
        //     Employee_SerialNumber: "",
        //     Employee_ID_Number: "",
        //     ID_Front: '',
        //     ID_Back: '',
        //     Validity_EndDate: '',
        //     Row_Status: '',
        //     Operation_ID: '',
        //     Operation_Datetime: '',
        //   }],
        // }
      },
      loading: false
    }
  },
  mounted() {

  },
  methods: {
    submitForm(formName) {
      let _this = this
      this.$refs[formName].validate((valid) => {
        if (valid) {
          _this.loading = true
          $.ajax({
            url: DomainName + '/GoodsFileAdd',
            type: 'POST',
            data: {
              Data: JSON.stringify({
                employee: [_this.form]
              }),
              token: $.cookie("token")
            },
            success: function (res) {
              if (res.Status === 'success') {
                _this.$message.success("提交成功")
                window.location.href = './Employee.html'
              } else {
                _this.$message.error("提交失败，请稍后再试")
              }
            },
            error: function () {
              _this.$message.error("操作失败，请稍后再试")
            },
            complete: function (XMLHttpRequest) {
              _this.loading = false
              if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
              }
            }
          })
        } else {
          console.log("error submit!!");
          return false;
        }

      });
    },
  }
})